portal = {
    URL : {
        loginURL : function (userName,pwd) {
            return "/u/l/"+userName+"/"+pwd+"/doLogin";

        }

    },
    login : {
        init : function(loginInfo){
            //获取元素中的值

            if(portal.inputCheck(loginInfo['userName'],loginInfo['pwd'])){
                //身份验证
                portal.verification(loginInfo);
            }else{
                return false;
            }

        }
    },
    inputCheck : function(userName,pwd){//验证输入格式
        if(userName == ""){
            $("#userName").focus();
            $("#userNameWarning").html("用户名不能为空！");
            $("#userNameWarning").css("visibility","visible");
            return false;
        }else if(pwd == ""){
            $("#pwd").focus();
            $("#pwdWarning").html("密码不能为空！");
            $("#pwdWarning").css("visibility","visible");
            return false;
        }else if(pwd.length<6){
            $("#pwd").focus();
            $("#pwdWarning").html("密码长度不行大于6位！");
            $("#pwdWarning").css("visibility","visible");
            return false;
        }else{
            return true;
        }
    },
    verification : function(loginInfo){
        //ajax请求doLogin返回的json:{success,data{loginUserName,loginPwd}}
        $.ajax({
            type: "POST",
            url: portal.URL.loginURL(loginInfo['userName'], loginInfo['pwd']),
            data: {},
            dataType: "json",
            success: function(result){
                var data = result['data'];
                if(result['success']){
                    //登录成功
                    if(loginInfo['doSave']){
                        //将密码存入cookie中
                        $.cookie("userName",data.loginUserName,{expires:7,path:"/"});
                        $.cookie("pwd",data.loginPwd,{expires:7,path:"/"});
                    }
                    window.location.assign("/u/h/home");
                }else{
                    //登录未成功
                    $("#userNameWarning").css("visibility","hidden");
                    $("#pwdWarning").css("visibility","hidden");
                    if(data.loginUserName != ""){
                        $("#userNameWarning").html(data.loginUserName);
                        $("#userNameWarning").css("visibility","visible");
                    }
                    if(data.loginPwd != ""){
                        $("#pwdWarning").html(data.loginPwd);
                        $("#pwdWarning").css("visibility","visible");
                    }

                }
            },
            error: function(){
                alert("服务器出错！");
            }
        });
        //显示错误信息

    }
}